package com.health.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.health.service.MemberService;
import com.health.service.OrderService;
import com.health.service.SetMealService;
import com.health.utils.DateUtil;
import com.health.vo.Result;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * 统计数据显示
 */
@RestController
@RequestMapping("/home")
public class HomeController {

    @Reference
    private MemberService memberService;

    @Reference
    private OrderService orderService;

    @Reference
    private SetMealService setMealService;

    /**
     * 查询会员数量
     */
    @GetMapping("/findMemberCount")
    public Result findMemberCount(@DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                                  @DateTimeFormat(pattern = "yyyy-MM-dd") Date end) {

        //获取日期字符集合
        List<String> stringList = DateUtil.getStringList(start, end);

        //获取起始日期
        String firstDay = stringList.get(0);
        //创建临时数组，用于遍历sql
        int[] arr = new int[stringList.size()-1];
        //查询每日会员数量
        List<Integer> countList = memberService.findCountByDate(firstDay,arr);

        //封装数据
        Map<String, Object> map = new HashMap<>();
        map.put("stringList", stringList);
        map.put("countList", countList);

        return new Result(true, "查询会员数量成功", map);
    }

    /**
     * 查询套餐预订数量
     */
    @GetMapping("/findSetMealCount")
    public Result findSetMealCount(@DateTimeFormat(pattern = "yyyy-MM-dd") Date start,
                                   @DateTimeFormat(pattern = "yyyy-MM-dd") Date end) {

        List<Map<String, Object>> list = setMealService.findSetMealCount(start, end);
        return new Result(true, "查询套餐预订数量成功", list);
    }

    /**
     * 查询热门套餐数据报告
     * 预订数量前3的套餐
     */
    @GetMapping("/findSetMealReport")
    public Result findSetMealReport() {
        List<Map<String, Object>> list = setMealService.findSetMealReport();
        return new Result(true, "查询热门套餐数据报告成功", list);
    }

    /**
     * 查询预约到诊数据报告
     */
    @GetMapping("/findOrderReport")
    public Result findOrderReport() {
        Map<String, Object> map = orderService.findOrderReport();
        return new Result(true, "查询预约到诊数据报告成功", map);
    }
    /**
     * 查询会员数据报告
     */
    @GetMapping("/findMemberReport")
    public Result findMemberReport(){
        Map<String,Object> map=memberService.findMemberReport();

        return new Result(true,"查询会员数据成功",map);
    }
}
